package pt.ist.meic.pava;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


public class MyLock {
	private static MyLock instance;
	private static Object syncPoint = new Object();
	private Lock myLock;
	
	private MyLock(Lock l){
		this.myLock = l;
	}
	
	public void lock(){
		if(this.myLock != null)
			this.myLock.lock();
		else
			System.err.println("LOCK A NULL");
	}
	
	public void Unlock(){
		if(this.myLock != null)
			this.myLock.unlock();
		else
			System.err.println("UNLOCK A NULL");
	}
	
	
	public static MyLock getInstance(){
		synchronized (syncPoint){
			if(MyLock.instance == null){
				MyLock.instance = new MyLock(new ReentrantLock());
			}
		}
		return MyLock.instance;
	}
}
